#include <iostream>
#include <algorithm>
using namespace std;

typedef struct node
{
    int degree;
    int index;
} Fuck;

bool cmp(Fuck a, Fuck b)
{
    return a.degree > b.degree;
}

int main()
{
    ios::sync_with_stdio(false);
    int T, N, i, j, x, y;
    long sum;
    bool found = false;
    struct node neighbors[101];
    int edges[10][10];
    cin >> T;
    while (T--)
    {
        cin >> N;
        sum = 0;
        found = true;
        for (i = 0; i < N; i++)
        {
            cin >> neighbors[i].degree;
            neighbors[i].index = i;
            sum += neighbors[i].degree;
        }
        if (sum & 1)
        {
            found = false;
        }
        else
        {
            for (i = 0; i < N; i++)
            {
                for (j = 0; j < N; j++)
                {
                    edges[i][j] = 0;
                }
            }
            for (i = 0; i < N; i++)
            {
                sort(neighbors, neighbors + N, cmp);
                if (neighbors[0].degree == 0)
                {
                    found = true;
                    break;
                }
                for (j = 0; j < neighbors[0].degree; j++)
                {
                    neighbors[j + 1].degree--;
                    x = neighbors[0].index;
                    y = neighbors[j + 1].index;
                    if (neighbors[j + 1].degree < 0)
                    {
                        found = false;
                        break;
                    }
                    edges[x][y] = edges[y][x] = 1;
                }
                neighbors[0].degree = 0;
                if (found == false)
                {
                    break;
                }
            }
        }
        if (found)
        {
            cout << "YES" << endl;
            for (i = 0; i < N; i++)
            {
                for (j = 0; j < N; j++)
                {
                    cout << edges[i][j] << " ";
                }
                cout << endl;
            }
        }
        else
        {
            cout << "NO" << endl;
        }
        cout << endl;
    }
    return 0;
}